import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
tips.head(5)
| total_bill | tip | sex | smoker | day | time | size | |
|---|---|---|---|---|---|---|---|
| 0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
| 1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
| 2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
| 3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
| 4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
plt.scatter(tips["total_bill"], tips["tip"])
<matplotlib.collections.PathCollection at 0x7f9b1c5c4910>
sns.relplot(data=tips,
x="total_bill",
y="tip"
)
<seaborn.axisgrid.FacetGrid at 0x7f9b1c5fa0d0>
sns.set_theme(style="darkgrid",
palette="colorblind",
font_scale=1.3
)
sns.relplot(data=tips,
x="total_bill",
y="tip"
)
<seaborn.axisgrid.FacetGrid at 0x7f9b1c725fa0>
sns.relplot(data=tips,
x="total_bill",
y="tip",
height=6,
aspect=2
)
<seaborn.axisgrid.FacetGrid at 0x7f9b1c8e2490>
sns.relplot(data=tips,
x="total_bill",
y="tip",
hue="day",
height=6,
aspect=2
)
<seaborn.axisgrid.FacetGrid at 0x7f9b1c6310a0>
sns.relplot(data=tips,
x="total_bill",
y="tip",
hue="day",
size="size",
sizes=(5, 400),
height=6,
aspect=2
)
<seaborn.axisgrid.FacetGrid at 0x7f9b1cfe9d30>
sns.relplot(data=tips,
x="total_bill",
y="tip",
hue="day",
size="size",
col="time",
sizes=(5, 400),
height=6,
aspect=1
)
<seaborn.axisgrid.FacetGrid at 0x7f9b1d6e73a0>
sns.relplot(data=tips,
x="total_bill",
y="tip",
hue="day",
size="size",
col="time",
row="sex",
sizes=(5, 400),
height=4,
aspect=1
)
<seaborn.axisgrid.FacetGrid at 0x7f9b1db51370>
g = sns.jointplot(data=tips, x="total_bill", y="tip", height=7)
g.set_axis_labels("Total bill", "Tip")
g.fig.suptitle("Restaurant visits", y=1.01)
Text(0.5, 1.01, 'Restaurant visits')
plt.figure(figsize=(10, 7))
plt.subplot(1, 2, 1)
sns.scatterplot(data=tips,
x="total_bill",
y="tip",
hue="day"
)
plt.xlabel("Total bill")
plt.ylabel("Tip")
plt.plot([0, 50], [1, 10], 'r-', lw=5)
plt.subplot(1, 2, 2)
plt.plot([1, 2, 3, 4], [3, 0, 2, 1], 'bo-')
[<matplotlib.lines.Line2D at 0x7f9b1e54d820>]
%pip install plotly
Requirement already satisfied: plotly in /Users/bb/opt/anaconda3/lib/python3.8/site-packages (4.14.1) Requirement already satisfied: six in /Users/bb/opt/anaconda3/lib/python3.8/site-packages (from plotly) (1.15.0) Requirement already satisfied: retrying>=1.3.3 in /Users/bb/opt/anaconda3/lib/python3.8/site-packages (from plotly) (1.3.3) Note: you may need to restart the kernel to use updated packages.
import plotly.express as px
fig = px.scatter(data_frame=tips,
x="total_bill",
y="tip",
title="Restaurant data",
width=800,
height=400
)
fig.show()
fig = px.scatter(data_frame=tips,
x="total_bill",
y="tip",
color="day",
title="Restaurant data",
width=1000,
height=500
)
fig.show()
fig = px.scatter(data_frame=tips,
x="total_bill",
y="tip",
color="day",
size="size",
title="Restaurant data",
width=1000,
height=500
)
fig.show()
fig = px.scatter(data_frame=tips,
x="total_bill",
y="tip",
color="day",
size="size",
facet_col="time",
title="Restaurant data",
width=1000,
height=500
)
fig.show()
fig = px.scatter(data_frame=tips,
x="total_bill",
y="tip",
color="day",
size="size",
facet_col="time",
facet_row="sex",
title="Restaurant data",
width=1000,
height=500
)
fig.show()
fig.write_html("my_plot.html")
gapminder = px.data.gapminder()
gapminder.sample(5)
| country | continent | year | lifeExp | pop | gdpPercap | iso_alpha | iso_num | |
|---|---|---|---|---|---|---|---|---|
| 861 | Kuwait | Asia | 1997 | 76.15600 | 1765345 | 40300.619960 | KWT | 414 |
| 511 | Ethiopia | Africa | 1987 | 46.68400 | 42999530 | 573.741314 | ETH | 231 |
| 611 | Guatemala | Americas | 2007 | 70.25900 | 12572928 | 5186.050003 | GTM | 320 |
| 1507 | Taiwan | Asia | 1987 | 73.40000 | 19757799 | 11054.561750 | TWN | 158 |
| 289 | China | Asia | 1957 | 50.54896 | 637408000 | 575.987001 | CHN | 156 |
ac = gapminder[gapminder["country"].str[0] == "A" ]
ac.sample(10)
| country | continent | year | lifeExp | pop | gdpPercap | iso_alpha | iso_num | |
|---|---|---|---|---|---|---|---|---|
| 62 | Australia | Oceania | 1962 | 70.930 | 10794968 | 12217.226860 | AUS | 36 |
| 30 | Algeria | Africa | 1982 | 61.368 | 20033753 | 5745.160213 | DZA | 12 |
| 19 | Albania | Europe | 1987 | 72.000 | 3075321 | 3738.932735 | ALB | 8 |
| 48 | Argentina | Americas | 1952 | 62.485 | 17876956 | 5911.315053 | ARG | 32 |
| 17 | Albania | Europe | 1977 | 68.930 | 2509048 | 3533.003910 | ALB | 8 |
| 67 | Australia | Oceania | 1987 | 76.320 | 16257249 | 21888.889030 | AUS | 36 |
| 27 | Algeria | Africa | 1967 | 51.407 | 12760499 | 3246.991771 | DZA | 12 |
| 9 | Afghanistan | Asia | 1997 | 41.763 | 22227415 | 635.341351 | AFG | 4 |
| 24 | Algeria | Africa | 1952 | 43.077 | 9279525 | 2449.008185 | DZA | 12 |
| 37 | Angola | Africa | 1957 | 31.999 | 4561361 | 3827.940465 | AGO | 24 |
fig = px.line(ac,
x="year",
y="gdpPercap",
color="country",
hover_name="country",
labels={"year": "Year", "gdpPercap": "GDP per capita", "country": "Country name"}
)
fig.show()
fig = px.bar(tips,
x="day",
y="total_bill",
color="sex",
barmode="group",
category_orders = {"day": ["Thur", "Fri", "Sat", "Sun"]}
)
fig.show()
fig = px.strip(tips,
x="day",
y="tip",
color="sex",
category_orders = {"day": ["Thur", "Fri", "Sat", "Sun"]}
)
fig.show()
fig = px.histogram(tips,
x='total_bill',
nbins=30,
histnorm="percent"
)
fig.update_layout({"bargap": 0.02})
fig.show()
fig = px.scatter_3d(tips,
x = "total_bill",
y="tip",
z="size",
color="day"
)
fig.show()
url = "https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv"
import pandas as pd
df = pd.read_csv(url)
df.head(5)
| code | state | category | total exports | beef | pork | poultry | dairy | fruits fresh | fruits proc | total fruits | veggies fresh | veggies proc | total veggies | corn | wheat | cotton | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | AL | Alabama | state | 1390.63 | 34.4 | 10.6 | 481.0 | 4.06 | 8.0 | 17.1 | 25.11 | 5.5 | 8.9 | 14.33 | 34.9 | 70.0 | 317.61 |
| 1 | AK | Alaska | state | 13.31 | 0.2 | 0.1 | 0.0 | 0.19 | 0.0 | 0.0 | 0.00 | 0.6 | 1.0 | 1.56 | 0.0 | 0.0 | 0.00 |
| 2 | AZ | Arizona | state | 1463.17 | 71.3 | 17.9 | 0.0 | 105.48 | 19.3 | 41.0 | 60.27 | 147.5 | 239.4 | 386.91 | 7.3 | 48.7 | 423.95 |
| 3 | AR | Arkansas | state | 3586.02 | 53.2 | 29.4 | 562.9 | 3.53 | 2.2 | 4.7 | 6.88 | 4.4 | 7.1 | 11.45 | 69.5 | 114.5 | 665.44 |
| 4 | CA | California | state | 16472.88 | 228.7 | 11.1 | 225.4 | 929.95 | 2791.8 | 5944.6 | 8736.40 | 803.2 | 1303.5 | 2106.79 | 34.6 | 249.3 | 1064.95 |
df["cotton_exports"] = df["cotton"] > 0
df.head(5)
| code | state | category | total exports | beef | pork | poultry | dairy | fruits fresh | fruits proc | total fruits | veggies fresh | veggies proc | total veggies | corn | wheat | cotton | cotton_exports | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | AL | Alabama | state | 1390.63 | 34.4 | 10.6 | 481.0 | 4.06 | 8.0 | 17.1 | 25.11 | 5.5 | 8.9 | 14.33 | 34.9 | 70.0 | 317.61 | True |
| 1 | AK | Alaska | state | 13.31 | 0.2 | 0.1 | 0.0 | 0.19 | 0.0 | 0.0 | 0.00 | 0.6 | 1.0 | 1.56 | 0.0 | 0.0 | 0.00 | False |
| 2 | AZ | Arizona | state | 1463.17 | 71.3 | 17.9 | 0.0 | 105.48 | 19.3 | 41.0 | 60.27 | 147.5 | 239.4 | 386.91 | 7.3 | 48.7 | 423.95 | True |
| 3 | AR | Arkansas | state | 3586.02 | 53.2 | 29.4 | 562.9 | 3.53 | 2.2 | 4.7 | 6.88 | 4.4 | 7.1 | 11.45 | 69.5 | 114.5 | 665.44 | True |
| 4 | CA | California | state | 16472.88 | 228.7 | 11.1 | 225.4 | 929.95 | 2791.8 | 5944.6 | 8736.40 | 803.2 | 1303.5 | 2106.79 | 34.6 | 249.3 | 1064.95 | True |
fig = px.choropleth(df,
locationmode="USA-states",
locations="code",
scope="usa",
color="cotton_exports",
color_discrete_sequence = ["red", "lightgray"],
title="States exporting cotton",
hover_name = "state",
hover_data = {"cotton_exports": False, "code": False}
)
fig.update_layout(showlegend=False)
fig.show()
import plotly.express as px
df["veggies_perc"] = (df["total veggies"]/df["total exports"])*100
df.head(3)
| code | state | category | total exports | beef | pork | poultry | dairy | fruits fresh | fruits proc | total fruits | veggies fresh | veggies proc | total veggies | corn | wheat | cotton | veggies_perc | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | AL | Alabama | state | 1390.63 | 34.4 | 10.6 | 481.0 | 4.06 | 8.0 | 17.1 | 25.11 | 5.5 | 8.9 | 14.33 | 34.9 | 70.0 | 317.61 | 1.030468 |
| 1 | AK | Alaska | state | 13.31 | 0.2 | 0.1 | 0.0 | 0.19 | 0.0 | 0.0 | 0.00 | 0.6 | 1.0 | 1.56 | 0.0 | 0.0 | 0.00 | 11.720511 |
| 2 | AZ | Arizona | state | 1463.17 | 71.3 | 17.9 | 0.0 | 105.48 | 19.3 | 41.0 | 60.27 | 147.5 | 239.4 | 386.91 | 7.3 | 48.7 | 423.95 | 26.443270 |
fig = px.choropleth(df,
locationmode="USA-states",
scope="usa",
locations="code",
color="veggies_perc",
title="Precentage of veggie exports",
color_continuous_scale = "tempo",
hover_name="state",
labels={"veggies_perc": "Veggie %"},
hover_data = {"code": False}
)
fig.update_traces(marker_line_color="white")
fig.show()
dir(px.colors.sequential)[:10]
['Aggrnyl', 'Aggrnyl_r', 'Agsunset', 'Agsunset_r', 'Blackbody', 'Blackbody_r', 'Bluered', 'Bluered_r', 'Blues', 'Blues_r']
from zipfile import ZipFile
import requests
import pandas as pd
# download names.zip
r = requests.get("https://www.ssa.gov/oact/babynames/names.zip")
with open("names.zip", 'wb') as foo:
foo.write(r.content)
# read zipped csv file
with ZipFile("names.zip", 'r') as z:
fnames = (f for f in z.namelist() if f.endswith(".txt"))
file_dict = {}
for f in fnames:
with z.open(f) as foo:
file_dict[int(f[3:-4])] = pd.read_csv(foo, names=["name", "sex", "count"])
# concatenate dataframes
df = pd.concat(file_dict.values(), keys=file_dict.keys())
df.reset_index(level=0, inplace=True)
df.rename({"level_0": "year"}, axis=1, inplace=True)
df
| year | name | sex | count | |
|---|---|---|---|---|
| 0 | 1880 | Mary | F | 7065 |
| 1 | 1880 | Anna | F | 2604 |
| 2 | 1880 | Emma | F | 2003 |
| 3 | 1880 | Elizabeth | F | 1939 |
| 4 | 1880 | Minnie | F | 1746 |
| ... | ... | ... | ... | ... |
| 31949 | 2019 | Zyheem | M | 5 |
| 31950 | 2019 | Zykel | M | 5 |
| 31951 | 2019 | Zyking | M | 5 |
| 31952 | 2019 | Zyn | M | 5 |
| 31953 | 2019 | Zyran | M | 5 |
1989401 rows × 4 columns
n_babies = df.groupby(by="year")["count"].sum()
n_babies
year
1880 201484
1881 192696
1882 221533
1883 216944
1884 243461
...
2015 3694784
2016 3661373
2017 3567022
2018 3503806
2019 3445321
Name: count, Length: 140, dtype: int64
px.line(x=n_babies.index, y=n_babies)
n_babies2 = df.groupby(by=["year", "sex"])["count"].sum()
n_babies2
year sex
1880 F 90994
M 110490
1881 F 91953
M 100743
1882 F 107847
...
2017 M 1845472
2018 F 1694640
M 1809166
2019 F 1665373
M 1779948
Name: count, Length: 280, dtype: int64
n_babies2 = n_babies2.reset_index()
n_babies2
| year | sex | count | |
|---|---|---|---|
| 0 | 1880 | F | 90994 |
| 1 | 1880 | M | 110490 |
| 2 | 1881 | F | 91953 |
| 3 | 1881 | M | 100743 |
| 4 | 1882 | F | 107847 |
| ... | ... | ... | ... |
| 275 | 2017 | M | 1845472 |
| 276 | 2018 | F | 1694640 |
| 277 | 2018 | M | 1809166 |
| 278 | 2019 | F | 1665373 |
| 279 | 2019 | M | 1779948 |
280 rows × 3 columns
px.line(n_babies2,
x="year",
y="count",
color="sex"
)
pd.pivot_table(n_babies2, index="year", columns="sex", values="count")
| sex | F | M |
|---|---|---|
| year | ||
| 1880 | 90994 | 110490 |
| 1881 | 91953 | 100743 |
| 1882 | 107847 | 113686 |
| 1883 | 112319 | 104625 |
| 1884 | 129019 | 114442 |
| ... | ... | ... |
| 2015 | 1781725 | 1913059 |
| 2016 | 1767902 | 1893471 |
| 2017 | 1721550 | 1845472 |
| 2018 | 1694640 | 1809166 |
| 2019 | 1665373 | 1779948 |
140 rows × 2 columns
john = df[df["name"] == "John"]
john
| year | name | sex | count | |
|---|---|---|---|---|
| 228 | 1880 | John | F | 46 |
| 942 | 1880 | John | M | 9655 |
| 312 | 1881 | John | F | 26 |
| 938 | 1881 | John | M | 8769 |
| 277 | 1882 | John | F | 40 |
| ... | ... | ... | ... | ... |
| 18426 | 2017 | John | M | 9499 |
| 7919 | 2018 | John | F | 14 |
| 18125 | 2018 | John | M | 9163 |
| 8290 | 2019 | John | F | 13 |
| 17932 | 2019 | John | M | 8779 |
280 rows × 4 columns
john = john.drop("name", axis=1)
john
| year | sex | count | |
|---|---|---|---|
| 228 | 1880 | F | 46 |
| 942 | 1880 | M | 9655 |
| 312 | 1881 | F | 26 |
| 938 | 1881 | M | 8769 |
| 277 | 1882 | F | 40 |
| ... | ... | ... | ... |
| 18426 | 2017 | M | 9499 |
| 7919 | 2018 | F | 14 |
| 18125 | 2018 | M | 9163 |
| 8290 | 2019 | F | 13 |
| 17932 | 2019 | M | 8779 |
280 rows × 3 columns
px.line(john, x="year", y="count", color="sex")
fig = px.line(john, x="year", y="count", color="sex", facet_row="sex")
fig.update_yaxes(matches=None)
fig.show()
n_babies2
| year | sex | count | |
|---|---|---|---|
| 0 | 1880 | F | 90994 |
| 1 | 1880 | M | 110490 |
| 2 | 1881 | F | 91953 |
| 3 | 1881 | M | 100743 |
| 4 | 1882 | F | 107847 |
| ... | ... | ... | ... |
| 275 | 2017 | M | 1845472 |
| 276 | 2018 | F | 1694640 |
| 277 | 2018 | M | 1809166 |
| 278 | 2019 | F | 1665373 |
| 279 | 2019 | M | 1779948 |
280 rows × 3 columns
john_tot = john.groupby(by="year")["count"].sum()
john_tot
year
1880 9701
1881 8795
1882 9597
1883 8934
1884 9428
...
2015 10407
2016 10044
2017 9509
2018 9177
2019 8792
Name: count, Length: 140, dtype: int64
john_ratio = john_tot/n_babies
john_ratio
year
1880 0.048148
1881 0.045642
1882 0.043321
1883 0.041181
1884 0.038725
...
2015 0.002817
2016 0.002743
2017 0.002666
2018 0.002619
2019 0.002552
Name: count, Length: 140, dtype: float64
px.line(x = john_ratio.index, y=john_ratio)
df
| year | name | sex | count | |
|---|---|---|---|---|
| 0 | 1880 | Mary | F | 7065 |
| 1 | 1880 | Anna | F | 2604 |
| 2 | 1880 | Emma | F | 2003 |
| 3 | 1880 | Elizabeth | F | 1939 |
| 4 | 1880 | Minnie | F | 1746 |
| ... | ... | ... | ... | ... |
| 31949 | 2019 | Zyheem | M | 5 |
| 31950 | 2019 | Zykel | M | 5 |
| 31951 | 2019 | Zyking | M | 5 |
| 31952 | 2019 | Zyn | M | 5 |
| 31953 | 2019 | Zyran | M | 5 |
1989401 rows × 4 columns
def top_name(grp):
return grp.sort_values(by="count", ascending=False).head(1)
most_popular = df.groupby(by=["year", "sex"]).apply(top_name)
most_popular
| year | name | sex | count | |||
|---|---|---|---|---|---|---|
| year | sex | |||||
| 1880 | F | 0 | 1880 | Mary | F | 7065 |
| M | 942 | 1880 | John | M | 9655 | |
| 1881 | F | 0 | 1881 | Mary | F | 6919 |
| M | 938 | 1881 | John | M | 8769 | |
| 1882 | F | 0 | 1882 | Mary | F | 8148 |
| ... | ... | ... | ... | ... | ... | ... |
| 2017 | M | 18400 | 2017 | Liam | M | 18821 |
| 2018 | F | 0 | 2018 | Emma | F | 18757 |
| M | 18100 | 2018 | Liam | M | 19915 | |
| 2019 | F | 0 | 2019 | Olivia | F | 18451 |
| M | 17905 | 2019 | Liam | M | 20502 |
280 rows × 4 columns
most_popular = most_popular.reset_index(level=2, drop=True)
most_popular
| year | name | sex | count | ||
|---|---|---|---|---|---|
| year | sex | ||||
| 1880 | F | 1880 | Mary | F | 7065 |
| M | 1880 | John | M | 9655 | |
| 1881 | F | 1881 | Mary | F | 6919 |
| M | 1881 | John | M | 8769 | |
| 1882 | F | 1882 | Mary | F | 8148 |
| ... | ... | ... | ... | ... | ... |
| 2017 | M | 2017 | Liam | M | 18821 |
| 2018 | F | 2018 | Emma | F | 18757 |
| M | 2018 | Liam | M | 19915 | |
| 2019 | F | 2019 | Olivia | F | 18451 |
| M | 2019 | Liam | M | 20502 |
280 rows × 4 columns
most_popular = most_popular.drop(["year", "sex"], axis=1)
most_popular
| name | count | ||
|---|---|---|---|
| year | sex | ||
| 1880 | F | Mary | 7065 |
| M | John | 9655 | |
| 1881 | F | Mary | 6919 |
| M | John | 8769 | |
| 1882 | F | Mary | 8148 |
| ... | ... | ... | ... |
| 2017 | M | Liam | 18821 |
| 2018 | F | Emma | 18757 |
| M | Liam | 19915 | |
| 2019 | F | Olivia | 18451 |
| M | Liam | 20502 |
280 rows × 2 columns
most_popular["name"].unstack().T
| year | 1880 | 1881 | 1882 | 1883 | 1884 | 1885 | 1886 | 1887 | 1888 | 1889 | ... | 2010 | 2011 | 2012 | 2013 | 2014 | 2015 | 2016 | 2017 | 2018 | 2019 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| sex | |||||||||||||||||||||
| F | Mary | Mary | Mary | Mary | Mary | Mary | Mary | Mary | Mary | Mary | ... | Isabella | Sophia | Sophia | Sophia | Emma | Emma | Emma | Emma | Emma | Olivia |
| M | John | John | John | John | John | John | John | John | John | John | ... | Jacob | Jacob | Jacob | Noah | Noah | Noah | Noah | Liam | Liam | Liam |
2 rows × 140 columns
presidents = pd.DataFrame([{"name": "Obama", "start": "2007", "end": "2017"},
{"name": "Trump", "start": "2017", "end": "2021"},
])
presidents
| name | start | end | |
|---|---|---|---|
| 0 | Obama | 2007 | 2017 |
| 1 | Trump | 2017 | 2021 |
px.timeline(presidents,
x_start="start",
x_end="end",
y="name"
)
most_popular = most_popular.reset_index()
most_popular
| year | sex | name | count | |
|---|---|---|---|---|
| 0 | 1880 | F | Mary | 7065 |
| 1 | 1880 | M | John | 9655 |
| 2 | 1881 | F | Mary | 6919 |
| 3 | 1881 | M | John | 8769 |
| 4 | 1882 | F | Mary | 8148 |
| ... | ... | ... | ... | ... |
| 275 | 2017 | M | Liam | 18821 |
| 276 | 2018 | F | Emma | 18757 |
| 277 | 2018 | M | Liam | 19915 |
| 278 | 2019 | F | Olivia | 18451 |
| 279 | 2019 | M | Liam | 20502 |
280 rows × 4 columns
most_popular["start_year"] = (most_popular["year"]).astype(str)
most_popular["end_year"] = (most_popular["year"] + 1).astype(str)
most_popular
| year | sex | name | count | start_year | end_year | |
|---|---|---|---|---|---|---|
| 0 | 1880 | F | Mary | 7065 | 1880 | 1881 |
| 1 | 1880 | M | John | 9655 | 1880 | 1881 |
| 2 | 1881 | F | Mary | 6919 | 1881 | 1882 |
| 3 | 1881 | M | John | 8769 | 1881 | 1882 |
| 4 | 1882 | F | Mary | 8148 | 1882 | 1883 |
| ... | ... | ... | ... | ... | ... | ... |
| 275 | 2017 | M | Liam | 18821 | 2017 | 2018 |
| 276 | 2018 | F | Emma | 18757 | 2018 | 2019 |
| 277 | 2018 | M | Liam | 19915 | 2018 | 2019 |
| 278 | 2019 | F | Olivia | 18451 | 2019 | 2020 |
| 279 | 2019 | M | Liam | 20502 | 2019 | 2020 |
280 rows × 6 columns
fig = px.timeline(most_popular,
x_start="start_year",
x_end="end_year",
y="name",
color="sex",
facet_row = "sex"
)
fig.update_yaxes(matches=None)
fig.show()